using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 玩家动画结束触发器类
public class PlayerAnimationFinishTrigger : MonoBehaviour
{
    // 获取父对象中的Player组件，只读变量
    private Player player => GetComponentInParent<Player>();

    // 取消连续动画，挂在动画物体上
    private void AnimationFinishTrigger()
    {
        player.AnimationFinishTrigger();
    }

    // 攻击帧
    private void AttackTrigger()
    {
        AudioManager.instance.PlaySFX(2,null);
        // 获取攻击圆圈内所有碰撞体
        Collider2D[] colliders = Physics2D.OverlapCircleAll(player.attackCheck.position, player.attackCheckRadius);

        foreach (var hit in colliders)
        {
            // 判断是否是敌人
            if (hit.GetComponent<Enemy>() != null)
            {
                // 获取敌人状态
                EnemyStats _target = hit.GetComponent<EnemyStats>();
                if (_target != null)
                    // 对敌人造成伤害
                    player.stats.DoDamage(_target);
                // 对敌人造成武器效果，判断是否有武器
                Inventory.instance.GetEquipment(EquipmentType.Weapon)?.ExecuteItemEffect(_target.transform);
            }
        }
    }

    // 投掷动画结束时扔剑
    private void ThrowSword()
    {
        SkillManager.instance.sword.CreateSword();
    }
}